package com.ruoyi.flowable.listener.scrap;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.equ.domain.EquScrap;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 报废-4-3监听：大型设备处置
 */
@Slf4j
@Component("scrapListener_4_3")
public class ScrapListener_4_3 implements ExecutionListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void notify(DelegateExecution execution) {
        try {
            String code7_3 = execution.getVariable("code7_3", String.class);
            HashMap<String, Object> bigMap = new HashMap<>();
            bigMap.put("卫生行政部门备案编号", code7_3);
            //赋值
            EquScrap equScrap = execution.getVariable("equScrap", EquScrap.class);

            HashMap<String, Object> disposalInfoMap = new HashMap<>();
            disposalInfoMap.put("大型设备处置", bigMap);
            String disposalInfo = objectMapper.writeValueAsString(disposalInfoMap);

            equScrap.setDisposalInfo(disposalInfo);

            execution.setVariable("equScrap", equScrap);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
